package gjw.jimven.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import gjw.jimven.R;
import gjw.jimven.manager.ActivityManagers;

/**
 * @创建者 Jimven
 * @创建时间 2017/8/18/0018  15:35
 */
public abstract class BaseActivity extends AppCompatActivity {

    private   ActivityManagers mActivityManagers;
    protected Context          mContext;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //设置布局文件id
        setContentView(setLayoutId());
        mContext = this;

        //setUpStatusBarTintColor();
        //获取Activity的管理者
        mActivityManagers = ActivityManagers.getIntence();
        //把Activity加进管理中
        mActivityManagers.addActivity(this);
        setUpView();//设置布局

    }


    /**
     * 设置布局文件id
     */
    abstract protected int setLayoutId();

    /**
     * 设置布局
     */
    abstract protected void setUpView();


    /**
     * onDestroy方法，移除所有的Activity
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
        //移除所有的Activity
        mActivityManagers.removeActivity(this);
    }


    /**
     * 初始化状态栏颜色
     */
    private void setUpStatusBarTintColor() {
        getWindow().getDecorView().setBackgroundResource(R.color.mycolorPrimary);
    }
}
